#!/usr/bin/perl -wT

# cord@debian.org

require 5.001;
use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;

umask 002;

my $reviewlog='/org/lists.debian.org/spam-log/spam-review.log';
my $list;
my $year;
my $month;
my $article;
my $q = new CGI;

print $q->header;
my @names = $q->param;

my $list = (split ('/', $names[0]))[0];

open (HEADER, "/org/lists.debian.org/html/header.in") or 
  die ("$0: can't open /org/lists.debian.org/html/header.in: $!\n");
while (<HEADER>) {
  s/u_TITLE_u/Listarchive Review accepted/;
  print "<meta http-equiv=\"refresh\" content=\"0; URL=/cgi-bin/review/review2.pl?$list\">\n" if (m#^</head>$# and param('Send & Continue'));
  print;
}
close (HEADER);

print "<h2>Thank You</h2>\n";
print "<hr noshade width=\"100%\" size=\"1\">\n";

open (LOG, ">>$reviewlog") or die "$0: can't open $reviewlog for writing: $!\n";
my $time = time;
foreach my $post (@names) {
  if ($post =~ m#^(([\w\-]+)/(\d+)/(\d+)/(msg\d+.html))$#) {
#    my $path = $1;
    $list = $2;
    $year = $3;
    $month = $4;
    $article = $5;
  } elsif ($post =~ m#^(([\w\-]+)/(\d+)//(msg\d+.html))$#) {
    $list = $2;
    $year = $3;
    $month = '';
    $article = $4;
  } else {
    next;
  }
  next unless $q->param($post) =~ m#^(\w+)$#;
  my $rating = $1;
  print LOG "time: $time; addr: $ENV{'REMOTE_ADDR'}; list: $list, date: $year/$month, msg: $article, rating: $rating, reviewer: " . remote_user() . "\n";
  print "<li><a href=\"https://lists.debian.org/$post\" target=\"_blank\">https://lists.debian.org/$post</a> rated as $rating\n"; 
}

print "</ul>\n";

print "<p>continue: ";

print "<a href=\"/cgi-bin/review/review1.pl\">Debian mailarchive review</a>\n";
print "|| <a href=\"/cgi-bin/review/review2.pl?$list\">rate $list</a>" if $list;

open (FOOTER, "/org/lists.debian.org/html/footer.in") or 
  die ("$0: can't open /org/lists.debian.org/html/footer.in: $!\n");
while (<FOOTER>) {
  print;
}
close (FOOTER);

exit 0;
